import type { VbenFormProps } from '#/adapter/form';
import type { FormSchemaExt } from '#/api/common/model/validateModel';

import { z } from '#/adapter/form';
import { RuleType } from '#/api/common/model/validateModel';
import { dateUtil } from '#/utils/dateUtil';
// 表单参数定义
export const formSchamas: VbenFormProps = {
  wrapperClass: 'grid-cols-12', // 24栅格,
  commonConfig: {
    formItemClass: 'col-span-12',
  },
  schema: [
    {
      fieldName: 'assertFalse2',
      label: 'assertFalse2',
      component: 'Switch',
      componentProps: {
        placeholder: '请选择',
      },
      formItemClass: 'col-span-6',
    },
    {
      fieldName: 'assertTrue2',
      label: 'assertTrue2',
      component: 'Switch',
      componentProps: {
        placeholder: '请选择',
      },
      formItemClass: 'col-span-6',
    },
    {
      fieldName: 'name',
      label: 'name',
      component: 'Input',
      componentProps: {
        placeholder: '请输入',
        allowClear: true,
      },
      formItemClass: 'col-span-4',
    },
    {
      fieldName: 'name2',
      label: 'name2',
      component: 'VbenInput',
      componentProps: {
        placeholder: '请输入',
        allowClear: true,
      },
      formItemClass: 'col-span-4',
    },
    {
      fieldName: 'email',
      label: 'email',
      component: 'Input',
      componentProps: {
        placeholder: '请输入',
        allowClear: true,
      },
      formItemClass: 'col-span-4',
    },

    {
      fieldName: 'mobile',
      label: 'mobile',
      component: 'Input',
      componentProps: {
        placeholder: '请输入',
        allowClear: true,
      },
      formItemClass: 'col-span-4',
    },

    {
      fieldName: 'mobile2',
      label: 'mobile2',
      component: 'Input',
      componentProps: {
        placeholder: '请输入',
        allowClear: true,
      },
      formItemClass: 'col-span-4',
    },
    {
      fieldName: 'notBlank',
      label: 'notBlank',
      component: 'Input',
      componentProps: {
        placeholder: '请输入',
        allowClear: true,
      },
      // rules: z.union(
      //   [
      //     // rules: z.intersection(
      //     z
      //       .string({
      //         required_error: '此项必填',
      //         invalid_type_error: '数据类型错误',
      //       })
      //       .startsWith('start', { message: 'start 5' }),
      //     z
      //       .string({
      //         required_error: '此项必填2',
      //         invalid_type_error: '数据类型错误2',
      //       })
      //       .endsWith('end', { message: 'end 2' }),
      //   ],
      //   { message: 'un' },
      // ),
      formItemClass: 'col-span-4',
    },
    {
      fieldName: 'notNull',
      label: 'notNull',
      // component: 'Input',
      component: 'InputNumber',
      componentProps: {
        placeholder: '请输入',
        allowClear: true,
      },

      formItemClass: 'col-span-4',
    },
    {
      fieldName: 'notNullLong',
      label: 'notNullLong',
      component: 'InputNumber',
      componentProps: {
        placeholder: '请输入',
        allowClear: true,
      },
      formItemClass: 'col-span-4',
    },
    {
      fieldName: 'null2',
      label: 'null2',
      component: 'InputNumber',
      componentProps: {
        placeholder: '请输入',
        allowClear: true,
      },
      formItemClass: 'col-span-4',
    },

    {
      fieldName: 'decimalMax',
      label: 'decimalMax',
      component: 'InputNumber',
      componentProps: {
        placeholder: '请输入',
        allowClear: true,
      },
      formItemClass: 'col-span-4',
    },
    {
      fieldName: 'decimalMin',
      label: 'decimalMin',
      component: 'InputNumber',
      componentProps: {
        placeholder: '请输入',
        allowClear: true,
      },
      formItemClass: 'col-span-4',
    },
    {
      fieldName: 'digits',
      label: 'digits',
      component: 'InputNumber',
      componentProps: {
        placeholder: '请输入',
        allowClear: true,
      },
      formItemClass: 'col-span-4',
    },
    {
      fieldName: 'max',
      label: 'max',
      component: 'InputNumber',
      componentProps: {
        placeholder: '请输入',
        allowClear: true,
      },
      formItemClass: 'col-span-4',
    },
    {
      fieldName: 'min',
      label: 'min',
      component: 'InputNumber',
      componentProps: {
        placeholder: '请输入',
        allowClear: true,
      },
      formItemClass: 'col-span-4',
    },

    {
      fieldName: 'futureDateTime',
      label: 'futureDateTime',
      component: 'DatePicker',
      componentProps: {
        placeholder: '请输入',
        allowClear: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'YYYY-MM-DD HH:mm:ss',
        showTime: { defaultValue: dateUtil('00:00:00', 'HH:mm:ss') },
      },
      formItemClass: 'col-span-4',
    },
    {
      fieldName: 'futureLocalDate',
      label: 'futureLocalDate',
      component: 'DatePicker',
      componentProps: {
        placeholder: '请输入',
        allowClear: true,
        format: 'YYYY-MM-DD',
        valueFormat: 'YYYY-MM-DD',
      },
      formItemClass: 'col-span-4',
    },
    {
      fieldName: 'futureDate',
      label: 'futureDate',
      component: 'DatePicker',
      componentProps: {
        placeholder: '请输入',
        allowClear: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'YYYY-MM-DD HH:mm:ss',
        showTime: { defaultValue: dateUtil('00:00:00', 'HH:mm:ss') },
      },
      formItemClass: 'col-span-4',
    },
    {
      fieldName: 'futureOrPresentDateTime',
      label: 'futureOrPresentDateTime',
      component: 'DatePicker',
      componentProps: {
        placeholder: '请输入',
        allowClear: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'YYYY-MM-DD HH:mm:ss',
        showTime: { defaultValue: dateUtil('00:00:00', 'HH:mm:ss') },
      },
      formItemClass: 'col-span-4',
    },
    {
      fieldName: 'pastDateTime',
      label: 'pastDateTime',
      component: 'DatePicker',
      componentProps: {
        placeholder: '请输入',
        allowClear: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'YYYY-MM-DD HH:mm:ss',
        showTime: { defaultValue: dateUtil('00:00:00', 'HH:mm:ss') },
      },
      formItemClass: 'col-span-4',
    },
    {
      fieldName: 'pastOrPresentDateTime',
      label: 'pastOrPresentDateTime',
      component: 'DatePicker',
      componentProps: {
        placeholder: '请输入',
        allowClear: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'YYYY-MM-DD HH:mm:ss',
        showTime: { defaultValue: dateUtil('00:00:00', 'HH:mm:ss') },
      },
      formItemClass: 'col-span-4',
    },

    {
      fieldName: 'negative',
      label: 'negative',
      component: 'InputNumber',
      componentProps: {
        placeholder: '请输入',
        allowClear: true,
      },
      formItemClass: 'col-span-4',
    },
    {
      fieldName: 'negativeOrZero',
      label: 'negativeOrZero',
      component: 'InputNumber',
      componentProps: {
        placeholder: '请输入',
        allowClear: true,
      },
      formItemClass: 'col-span-4',
    },
    {
      fieldName: 'positive',
      label: 'positive',
      component: 'InputNumber',
      componentProps: {
        placeholder: '请输入',
        allowClear: true,
      },
      formItemClass: 'col-span-4',
    },
    {
      fieldName: 'positiveOrZero',
      label: 'positiveOrZero',
      component: 'InputNumber',
      componentProps: {
        placeholder: '请输入',
        allowClear: true,
      },
      formItemClass: 'col-span-4',
    },
  ],
};

export const customRules: FormSchemaExt[] = [
  {
    fieldName: 'name',
    ruleType: RuleType.and,
    rules: z
      .string({
        required_error: '此项必填2',
        invalid_type_error: '数据类型错误2',
      })
      .startsWith('sss', { message: 'start' }),
  },
  {
    fieldName: 'name2',
    ruleType: RuleType.or,
    rules: z
      .string({
        required_error: '此项必填2',
        invalid_type_error: '数据类型错误2',
      })
      .endsWith('end', { message: 'end' }),
  },
  {
    fieldName: 'email',
    ruleType: RuleType.cover,
    rules: z
      .string({
        required_error: '此项必填2',
        invalid_type_error: '数据类型错误2',
      })
      .endsWith('eeee', { message: 'end' }),
  },
];
